﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CH.TestData.Common;
namespace CH.TestData.Provider
{
    [DataTypeName("数组")]
    public class ArrayProvider : IDataProvider
    {

        private string columnName;
       
        private string[] dataSource;
        public void SetDataSource(FlowLayoutPanel flp)
        {
            TextBox txtColumnName = flp.Controls.Find("txtColumnName", false).First() as TextBox;
            this.columnName = txtColumnName.Text;
            TextBox txtArray = flp.Controls.Find("txtArray", true).First() as TextBox;
            this.dataSource = txtArray.Text.Split('|');


        }
        public void CreateOption(FlowLayoutPanel flp)
        {
            Label lblc = new Label();
            lblc.Text = "字符串数组";
            lblc.Width = 30;
            lblc.Margin = new Padding(0, 7, 0, 0);
            flp.Controls.Add(lblc);

            TextBox txtFrom = new TextBox();
            txtFrom.Name = "txtArray";
            txtFrom.Width = flp.Width - 90;
            txtFrom.Text = "0|1|2|3|4";
            txtFrom.Margin = new Padding(0, 3, 0, 0);
            flp.Controls.Add(txtFrom);
        }

        public string GetNextValue()
        {
            int index = new Random().Next(0, dataSource.Count() - 1);
            string value = dataSource[index];
            if (value.IsNumber())
            {
                return value;
            }
            else
            {
                return "N'" + value + "'";
            }
        }
    }
}
